package com.sk.waste.app.adapters

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.sk.waste.app.R
import com.sk.waste.app.adapters.SliderAdapter.SliderViewHolder
import com.sk.waste.app.config.NetWorkConfig
import com.sk.waste.app.models.ImageModel

class SliderAdapter(val mContext: Context, val imageUrls: List<ImageModel>) : RecyclerView.Adapter<SliderViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SliderViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.adapter_slider, parent, false)
        return SliderViewHolder(view)
    }

    override fun onBindViewHolder(holder: SliderViewHolder, position: Int) {
        val item = imageUrls[position]
        Glide.with(mContext).load(NetWorkConfig.NET_URL_IMA_ROOT + item.img).transform(CenterCrop(), RoundedCorners(20)).error(R.mipmap.img_banner_default).into(holder.imageView);
    }

    override fun getItemCount(): Int {
        return imageUrls.size
    }

    class SliderViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var imageView: ImageView

        init {
            imageView = itemView.findViewById(R.id.vw_adapter_slider)
        }
    }
}